﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ParkingApp.ParkingSlot.Simulator.Lib;
using TechTalk.SpecFlow;
using FluentAssertions;
using ParkingApp.Lib;

namespace ParkingApp.Specs
{
    [Binding]
    public class RequeueParkingStep
    {
        Slot _parkingSlot = null;
        Parking _parking = new Parking();
        TicketDetail _ticket = null;
        string _illegalParkedVehiclePlateNumber = null;

        [Given(@"parking slot available")]
        public void GivenParkingSlotAvailable()
        {
            _parkingSlot = _parking.GetAvailableSlot();
            _parkingSlot.Should().NotBeNull();
            _ticket = _parking.AllocateParkingSlot(_parkingSlot, "abc123");
            _ticket.Should().NotBeNull();
        }

        [Given(@"environmental issues for parking slot")]
        public void GivenEnvironmentalIssuesForParkingSlot()
        {
            _parking.MakeSlotUnavailable(_ticket.Slot, Slot.NotAvailableReason.EnvironmentalIssues, null);
        }

        [When(@"call requeue")]
        public void WhenCallRequeue()
        {
           _ticket = _parking.ReAllocateParkingSlot(_ticket);
        }

        [Then(@"the result should be new parking slot")]
        public void ThenTheResultShouldBeNewParkingSlot()
        {
            _ticket.Should().NotBeNull();
        }

        [Given(@"parking slot not available")]
        public void GivenParkingSlotNotAvailable()
        {
            _parkingSlot = _parking.GetAvailableSlot();
            _parkingSlot.Should().NotBeNull();
            _ticket = _parking.AllocateParkingSlot(_parkingSlot, "abc123");
            _ticket.Should().NotBeNull();
        }
        [Given(@"illegaly parked vehicle ""(.*)""")]
        public void GivenIllegalyParkedVehicle(string plateNumber)
        {
            _illegalParkedVehiclePlateNumber = plateNumber;
            _parking.MakeSlotUnavailable(_ticket.Slot, Slot.NotAvailableReason.IllegalyParkedCar, plateNumber);
        }
        [Then(@"the result should be new and illegaly parked vehicle tagged")]
        public void ThenTheResultShouldBeNewAndIllegalyParkedVehicleTagged()
        {
            _ticket = _parking.ReAllocateParkingSlot(_ticket);
            _ticket.Should().NotBeNull();

            var taggedVehicle = IllegalyParkedVehicle.IllegalyParkedVehicleList.Find(a => a.PlateNumber == _illegalParkedVehiclePlateNumber);
            taggedVehicle.Should().NotBeNull();
        }

        
    }
}
